﻿namespace XGameLibrary.Controls
{
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;

    public class PictureBox : Control
    {
        public PictureBox(Texture2D image, Rectangle destination)
        {
            this.Image = image;
            this.DestinationRectangle = destination;
            this.SourceRectangle = new Rectangle(
                0,
                0,
                image.Width,
                image.Height);
            this.Color = Color.White;
        }

        public PictureBox(Texture2D image, Rectangle destination, Rectangle source) :
            this(image, destination)
        {
            this.SourceRectangle = source;
        }

        public Texture2D Image { get; set; }

        public Rectangle SourceRectangle { get; set; }

        public Rectangle DestinationRectangle { get; set; }

        public override void Update(GameTime gameTime)
        {
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(
                this.Image,
                this.DestinationRectangle,
                this.SourceRectangle,
                this.Color);
        }

        public override void HandleInput()
        {
        }

        public void SetPosition(Vector2 newPosition)
        {
            this.DestinationRectangle = new Rectangle(
                (int)newPosition.X,
                (int)newPosition.Y,
                this.SourceRectangle.Width,
                this.SourceRectangle.Height);
        }
    }
}
